<template>
  <div class="app-container" />
</template>

<script>
export default {
  name: 'FirstView',
  components: {},
  props: {
    loadingVisible: {
      type: Boolean,
      default: true
    },
    isSymbol: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      dataModel: new ht.DataModel()
    }
  },
  computed: {},
  watch: {
    loadingVisible: {
      deep: true,
      immediate: true,
      handler(loadingVisible) {
        if (!loadingVisible) {
          this.$nextTick(() => {
            this.initModel()
          })
        }
      }
    },
    isSymbol: {
      handler() {

      }
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    initModel() {
      // const that = this
      const { dataModel } = this
      const g3d = new ht.graph3d.Graph3dView(dataModel)
      g3d.setEye(-2e3, 2e3, 4e3)
      g3d.moveCamera([-56, 1080, 2600], [-24, -1000, -98], { duration: 1500 })
      g3d.setFar(1e5)
      g3d.deserialize('/json/firstView.json', (json, dm, gv, datas) => {
        const scene = json.scene
        gv.setCenter(scene.center)
        dm.each((t) => {
          const name = t.getDisplayName()
          if (name !== '文字' && name !== 'ht-icon') return
          dataModel.a('y', t.p3()[1])
          dataModel.a('direction', 'up')
          if (name === 'blink') {
            dataModel.a('direction', 'down')
          }
        })
      })

      // 文字动画效果
      dataModel.addScheduleTask({
        interval: 50,
        action: function(t) {
          // console.log('t:', t);
          const name = t.getDisplayName()
          if (name === '文字' || name === 'ht-icon') {
            const e = t.p3()[0]
            const a = t.p3()[1]
            const o = t.p3()[2]
            const i = dataModel.a('y') + 20
            const n = dataModel.a('direction')
            if (n === 'up') {
              t.p3([e, a + 1, o])
              if (a + 1 === i) {
                dataModel.a('direction', 'down')
              }
            }
            if (n === 'down') {
              t.p3([e, a - 1, o])

              if (a - 1 === t.a('y')) {
                dataModel.a('direction', 'up')
              }
            }
          }
        }
      })

      // 上下动画
      dataModel.addScheduleTask({
        interval: 150,
        action: function(t) {
          if (t.getDisplayName() === 'blink') {
            const e = 10 * t.s('shape3d.opacity')
            const a = dataModel.a('direction')
            if (a === 'down') {
              t.s('shape3d.opacity', (e - 1) / 10)
              if ((e - 1) / 10 == 0) {
                dataModel.a('direction', 'up')
              }
            }
            if (a === 'up') {
              t.s('shape3d.opacity', (1 + e) / 10)
              if ((1 + e) / 10 == 0.7) {
                dataModel.a('direction', 'down')
              }
            }
          }
        }
      })

      // 添加点击事件
      g3d.mi((t) => {
        if (t.data && t.data._pickId) {
          this.$emit('onClickProduct', t.data.getTag())
        }
      })

      g3d.addToDOM()
    }
  }
}
</script>

<style scoped lang='scss'>
  .test{
    background: #212121 url('/assets/htdesign/scene/skybox/vague_01.jpg') no-repeat center center / cover;
  }
</style>
